package com.atXiao.food.strategy;

import java.util.HashMap;
import java.util.Map;

/**
 * 策略模式工厂
 *
 * @author: lixiaoxiao
 * @date: 2024/1/10 16:43
 * @version: 1.0
 * @desc:
 */
public class PromotionStrategyFactory {

    private static Map<String, IPromotionStrategy> strategyMap = new HashMap<>();

    static {
        strategyMap.put(PromotionKey.COUPON,new CouponStrategy());
        strategyMap.put(PromotionKey.GROUPBUY,new GroupBuyStrategy());
        strategyMap.put(PromotionKey.CASHBACK,new CashbackStrategy());
        strategyMap.put(PromotionKey.EMPTY,new EmptyStrategy());
    }

    /**
     * 默认无优惠
     */
    private static final IPromotionStrategy nomalStrategy=new EmptyStrategy();

    /**
     * 获取策略模式key对应的策略模式（去除if-else代码）
     * @param promotionKey
     * @return
     */
    public static IPromotionStrategy getPromotionStrategy(String promotionKey){
        IPromotionStrategy strategy = strategyMap.get(promotionKey);
        return strategy==null?nomalStrategy:strategy;
    }



    /**
     * 策略模式Key
     */
    private interface PromotionKey{
        String COUPON="COUPON";
        String GROUPBUY="GROUPBUY";
        String CASHBACK="CASHBACK";
        String EMPTY="EMPTY";
    }


}
